package com.gluck.cases.core.modal.assemble;

import com.gluck.cases.core.modal.dto.AdminUserDTO;
import com.gluck.cases.core.modal.entity.AdminUser;
import com.gluck.cases.core.modal.req.AdminUserReq;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @ClassName AdminUserAssemble
 * @Desc TODO
 * @Author I am Gluck
 * @Date 2022/5/16 - 4:40 下午
 **/
public class AdminUserAssemble {

    public static AdminUser adminUserDTOConvertAdminUser(AdminUserDTO dto){
        AdminUser adminUser = new AdminUser();
        adminUser.setIsLocked(dto.getIsLocked());
        adminUser.setUsername(dto.getUsername());
        adminUser.setPassword(dto.getPassword());
        adminUser.setSalt(dto.getSalt());
        return adminUser;
    }

    public static AdminUser getUpdateAdminUserByDTO(AdminUserDTO dto, AdminUser adminUser){
        adminUser.setSalt(dto.getSalt());
        adminUser.setIsLocked(dto.getIsLocked());
        adminUser.setUpdatedAt(LocalDateTime.now());
        adminUser.setUsername(dto.getUsername());
        adminUser.setPassword(dto.getPassword());
        return adminUser;
    }

    public static AdminUserDTO adminUserReqConvertAdminUserDTO(AdminUserReq req){
        AdminUserDTO dto = new AdminUserDTO();
        dto.setUsername(req.getUsername());
        dto.setUpdatedAt(new Date());
        dto.setIsLocked(req.getIsLocked());
        return dto;
    }

    public static AdminUserDTO adminUserConvertAdminUserDTO(AdminUser adminUser){
        AdminUserDTO dto = new AdminUserDTO();
        dto.setUsername(adminUser.getUsername());
        dto.setIsLocked(adminUser.getIsLocked());
//        dto.setCreatedAt();
        return dto;
    }
}
